#include "mainwidget.h"
#include "ui_mainwidget.h"
#include <QDesktopWidget>
#include <QDebug>
#include <QCloseEvent>

mainWidget::mainWidget(QWidget *parent)
    : QWidget(parent)
    , ui(new Ui::mainWidget)
{
    ui->setupUi(this);
    m_keyboardshow=false;
    keydialog=nullptr;
}

mainWidget::~mainWidget()
{
    //    if(keydialog)
    qDebug()<<"mainwidget ~";
    if(keydialog)
        delete keydialog;
    delete ui;
}

//void mainWidget::closeEvent(QCloseEvent *event)
//{

//    if(keydialog)
//    {
//             keydialog->deleteLater();
//    }

//    event->accept();

//}

void mainWidget::on_pushButton_clicked()
{
    if(m_keyboardshow==false)
    {
        m_keyboardshow=true;
        if(keydialog)
        {
            qDebug()<<"keydialog exist";
            keydialog->deleteLater();
            //        keydialog->deleteLater();
        }
        keydialog = new keyboardDialog(ui->lineEdit,this);
        keydialog->show();
        keydialog->move((QApplication::desktop()->width())/2,(QApplication::desktop()->height()-keydialog->height()));
    }
    else
    {
        if(keydialog)
        {
            qDebug()<<"keydialog exist";
            keydialog->deleteLater();
            keydialog=nullptr;
            //        keydialog->deleteLater();
        }
        m_keyboardshow=false;
    }
}

